#ifndef COUNTRESITEM_H
#define COUNTRESITEM_H

#include <QGraphicsItem>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QFont>

class CountResItem : public QGraphicsItem
{
public:
    explicit CountResItem(int id,
                          const std::pair<int, int>& position,
                          float radius,
                          QGraphicsItem* parent = nullptr);

    QRectF boundingRect() const override;

    void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;

    // 样式设置方法
    void setPen(const QPen& pen) { m_pen = pen; }
    void setBrush(const QBrush& brush) { m_brush = brush; }
    void setTextPen(const QPen& pen) { m_textPen = pen; }
    void setFont(const QFont& font) { m_font = font; }

    // 物体属性访问方法
    int id() const { return m_id; }
    std::pair<int, int> position() const { return m_position; }
    float radius() const { return m_radius; }

protected:
    // 鼠标交互事件
    void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
    void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
    void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;

private:
    void setDefaultStyle()
    {
        m_pen = QPen(Qt::green, 2);
        m_brush = QBrush(QColor(0, 255, 0, 50));
        m_textPen = QPen(Qt::white);
        m_font.setPointSize(10);
        m_font.setBold(true);
    }

    const int m_id;
    const std::pair<int, int> m_position;
    const float m_radius;
    QPen m_pen;
    QBrush m_brush;
    QPen m_textPen;
    QFont m_font;
};

#endif // COUNTRESITEM_H
